package com.tianji.aigc.controller;


import com.tianji.aigc.domain.vo.ChatSessionVO;
import com.tianji.aigc.domain.vo.MessageVO;
import com.tianji.aigc.domain.vo.SessionVO;
import com.tianji.aigc.service.IChatSessionService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 对话session 前端控制器
 * </p>
 *
 * @author 东哥
 * @since 2025-07-21
 */
@RestController
@RequestMapping("/session")
@RequiredArgsConstructor
public class ChatSessionController {
    private final IChatSessionService chatSessionService;

    /**
     * 1- 新建会话(Day1 - 随堂1)
     */
    @PostMapping
    public SessionVO createSession(@RequestParam(value = "n", defaultValue = "3") Integer num) {
        return this.chatSessionService.createSession(num);
    }

    /**
     * 2- 换一换-热门问题(Day1 - 随堂2)
     */
    @GetMapping("hot")
    public List<SessionVO.Example> hot(@RequestParam(value = "n", defaultValue = "3") Integer num) {
        return this.chatSessionService.hot(num);
    }

    /**
     * 3、通过 会话ID 获取会话详情 - Day1 - 作业2
     * @param sessionId
     * @return
     */
    @GetMapping("{sessionId}")
    public List<MessageVO> getChatRecord(@PathVariable("sessionId") String sessionId){
        return this.chatSessionService.getChatRecord(sessionId);
    }

    /**
     * 4、查询历史会话列表 - Day3 - 随堂2
     * @return
     */
    @GetMapping("history")
    public Map<String,List<ChatSessionVO>> queryHistorySession(){
        return this.chatSessionService.queryHistorySession();
    }

    /**
     * 5、删除历史会话列表(mysql会话、redis会话记录)- Day3 - 练习1
     */
    @DeleteMapping("/history")
    public void deleteHistorySession(@RequestParam("sessionId") String sessionId) {
        this.chatSessionService.deleteHistorySession(sessionId);
    }

    /**
     * 6、更新历史会话标题- Day3 - 练习2
     */
    @PutMapping("/history")
    public void updateTitle(@RequestParam("sessionId") String sessionId,
                            @RequestParam("title") String title) {
        this.chatSessionService.updateTitle(sessionId, title);
    }
}
